cmake_minimum_required(VERSION 3.0)
project(sylar)

# 启用详细的 Makefile 输出
set(CMAKE_VERBOSE_MAKEFILE ON)
set(P ${PROJECT_SOURCE_DIR})

if(NOT DEFINED CMAKE_BUILD_PARALLEL_LEVEL)
    include(ProcessorCount)
    ProcessorCount(NUM_PROCESSORS)
    if(NUM_PROCESSORS GREATER 1)
        set(CMAKE_BUILD_PARALLEL_LEVEL ${NUM_PROCESSORS} CACHE STRING "Number of parallel build jobs" FORCE)
    endif()
endif()
# 设置 C++ 编译标志（保持你的原始配置，添加必要的标准支持）
set(CMAKE_CXX_FLAGS "$ENV{CXXFLAGS} -rdynamic -O0 -ggdb -std=c++11 -Wall -Wno-deprecated -Werror -Wno-unused-function")

# 定义库的源文件列表
set(LIB_SRC
    sylar/log.cc
    sylar/util.cc
    sylar/thread.cc
    sylar/singleton.cc
    sylar/comment.cc 
    sylar/config.cc   
    sylar/sylar.cc
    sylar/macor.cc
    sylar/fiber.cc
    sylar/nocopyable.cc
    sylar/macor.cc
    sylar/scheduler.cc
)

# 包含项目头文件目录
include_directories(${P})
# 配置 yaml-cpp 库的查找路径
set(yaml-cpp_DIR "/usr/local/lib64/cmake/yaml-cpp")
find_package(yaml-cpp REQUIRED)
# 构建共享库（sylar 库）
add_library(sylar SHARED ${LIB_SRC})
# 关键：sylar 库依赖 yaml-cpp 和 pthread，链接对应库
target_link_libraries(sylar yaml-cpp::yaml-cpp pthread)

# #构建 test_config 测试程序
# add_executable(test_config tests/test_config.cc)
# add_dependencies(test_config sylar)
# target_link_libraries(test_config sylar)

# 构建 test_thread 测试程序（与 test_config.cc 同目录）
# add_executable(test_thread tests/test_thread.cc)
# add_dependencies(test_thread sylar)
# target_link_libraries(test_thread sylar)

# add_executable(test_scheduler tests/test_scheduler.cc)
# add_dependencies(test_scheduler sylar)
# target_link_libraries(test_scheduler sylar)

add_executable(test_scheduler2 tests/test_scheduler2.cc)
add_dependencies(test_scheduler2 sylar)
target_link_libraries(test_scheduler2 sylar)
# add_executable(test_fiber4 tests/test_fiber4.cc)
# add_dependencies(test_fiber4 sylar)
# target_link_libraries(test_fiber4 sylar)

# add_executable(test_fiber2 tests/test_fiber2.cc)
# add_dependencies(test_fiber2 sylar)
# target_link_libraries(test_fiber2 sylar)
# （可选）构建静态库（如果需要）
# add_library(sylar_static STATIC ${LIB_SRC})
# set_target_properties(sylar_static PROPERTIES OUTPUT_NAME "sylar")
# target_link_libraries(sylar_static PRIVATE yaml-cpp::yaml-cpp pthread)  # 静态库也需链接 pthread

# 设置输出路径
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)  # 可执行文件输出到 bin 目录
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)      # 库文件输出到 lib 目录